<?php
namespace app\admin\model;
use think\Loader;
use think\Model;
use think\Validate;

class UserModel extends Model
{
    protected $pk = 'id';//主键
    //设置当前模型对应的完整数据表名称
    protected $table = 'fly_user';
    
    //后台用户中心数据
    public function userList()
    {
    	$userList = $this->select();
    	return $userList;
    }
    //用户总数
    public function total()
    {
        $userTotal = $this->count();
        return $userTotal;
    }
    //通过id获取用户的个人信息
    public function userfind($data)
    {
        $userInfo = $this->find($data);
        return $userInfo->data;
    }
    //通过传来的post 进行修改用户信息操作
    public function userEdit($data){
        //执行验证
        $validate = new Validate([
            'email'  => 'require',
            'name' => 'require'
        ],[
            'email.require'  => '请输入邮箱',
            'name.require' => '请输入昵称'
            ]
    );
        if (!$validate->check($data)) {
            return ['valid'=> 0,'msg'=>$validate->getError()];
        }
        
        // save方法第二个参数为更新条件
        $res = $this->save([
            'email'  =>$data['email'],
            'name'  =>$data['name'],
            'sign'  =>$data['sign']
        ],[$this->pk => $data['id']]);
        if($res){
            return ['valid'=>1, 'msg'=>'用户信息修改成功'];
        }else{
            return ['valid'=>0, 'msg'=>'用户信息修改失败'];

        }


    }






}